package servlet.dept;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DepartmentDao;
import entity.Department;

public class SearchDeptServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2723711604170533687L;

	public SearchDeptServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.setContentType("application/json;charset=utf-8");
//		PrintWriter out = response.getWriter();
//		String deptName = URLDecoder.decode(URLDecoder.decode(request.getParameter("deptName"), "UTF-8"), "UTF-8");
//		DepartmentDao departmentDao = null;
//		Department department = null;
//		StringBuffer deptJson = null;
//		try {
//			departmentDao = new DepartmentDao();
//			department = departmentDao.queryDept(deptName);
//			
//			deptJson = new StringBuffer("{\"department\":[");
//			if(department != null) {
//				// obj to json
//				deptJson.append("{");
//				deptJson.append("\"deptName\": \"").append(department.getDeptName()).append("\",");
//				deptJson.append("\"createDate\": \"").append(department.getCreateDate().toString()).append("\"");
//				deptJson.append("}]}");
//			} else {
//				deptJson.append("]}");
//			}
//			
//			
//		} catch (SQLException e) {
//			e.printStackTrace();
//		} finally {
//			out.print(deptJson.toString());
//			out.close();
//		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void init() throws ServletException {
	}

}
